<?php
/**
 * Created by PhpStorm.
 * User: aron
 * Date: 2019/5/7
 * Time: 10:03 AM
 */
include_once "../../Util/DebugUtil/DebugUtil.php";

$contact = array(
    "ID" => 1232,
    "name" => "xiaomin",
    "tel" => "12345678978",
    "email" => "xiaomin@qq.com",
);

// each 方法在7.3标记为废弃
$item = each($contact);
print_r($item);
// Output:
//Array
//(
//    [1] => 1232
//    [value] => 1232
//    [0] => ID
//[key] => ID
//)


DebugUtil::printDebugSeperator();
// list语言结构，类似于swift中元组的分解
$userInfo = array("123123", "xiaomin ");
list($userID, $userName) = $userInfo;
echo "\$userID = $userID \n";
echo "\$userName = $userName \n";


DebugUtil::printDebugSeperator();
// foreach
foreach ($contact as $item) {
    echo "\$item = $item \n";
}

DebugUtil::printDebugSeperator();
foreach ($contact as $index => $item) {
    echo "\$index = $index  \$item = $item \n";
}


DebugUtil::printDebugSeperator();
// 内置指针
{
    // 重置指针到开始位置
    reset($contact);
    // key方法获取当前位置的key
    $key = key($contact);
    // current方法获取当前位置的value
    $value = current($contact);
    while ($key) {
        echo "\$key = $key  \$value = $value \n";
        // 移动指针到下一个位置
        next($contact);
        $key = key($contact);
        $value = current($contact);
    }
}